package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.ydkj.a37e_mall.R;

/**
 * Created by Administrator on 2017/3/5.
 */

public class BankcarActivity extends BaseActivity {
    Activity mActivity;
    private ImageView img_back;
    private ListView lv_bankcard;
    String[] strings = {"工商银行", "农业银行", "中国银行", "建设银行", "交通银行", "邮储银行", "招商银行", "光大银行", "中信银行", "华夏银行",
            "浦发银行", "民生银行", "平安银行", "广发银行", "兴业银行", "北京银行", "上海银行"};
    private BandcardAdapter bandcardAdapter;
    private int code;

    @Override

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bank_card);
        mActivity = this;
        init();
    }

    private void init() {
        code = getIntent().getExtras().getInt("code");
        Log.e("ssss", "code==>" + code);
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        lv_bankcard = (ListView) mActivity.findViewById(R.id.lv_bankcard);
        bandcardAdapter = new BandcardAdapter();
        lv_bankcard.setAdapter(bandcardAdapter);
    }

    private class BandcardAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return strings.length;
        }

        @Override
        public Object getItem(int i) {
            return strings[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(final int positon, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.choose_address_listitem, null);
                vh = new ViewHolder();
                vh.bankname = (TextView) convertView.findViewById(R.id.bankname);
                vh.lly_bank = (LinearLayout) convertView.findViewById(R.id.lly_bank);

            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            convertView.setClickable(true);
            vh.bankname.setText(strings[positon]);
            vh.lly_bank.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if (code == 1) {
                        Log.e("ssss", "code==>" + code);
                        Intent intent = new Intent(mActivity, AddBankcardActivity.class);
                        intent.putExtra("name", strings[positon]);
                        setResult(Activity.RESULT_OK, intent);
                        finish();
                    } else if (code == 2) {
                        Log.e("ssss", "code==>" + code);
                        Intent intent = new Intent(mActivity, ApplyBusinessActivity.class);
                        intent.putExtra("name", strings[positon]);
                        setResult(Activity.RESULT_OK, intent);
                        finish();
                    } else if (code == 3) {
                        Log.e("ssss", "code==>" + code);
                        Intent intent = new Intent(mActivity, StoreManagementActivity.class);
                        intent.putExtra("name", strings[positon]);
                        setResult(Activity.RESULT_OK, intent);
                        finish();
                    }
                }
            });


            return convertView;
        }

        private class ViewHolder {
            public TextView bankname;
            public LinearLayout lly_bank;
        }
    }
}
